const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const nodeExternals = require('webpack-node-externals');
const merge = require('webpack-merge')

module.exports = {
    // context: __dirname + "/../../src",
    // devtool: 'cheap-module-eval-source-map',
    target: "node",
    entry: __dirname + '/brower/src/server_index.jsx',
    output: {
        filename: /*'main.[hash:6].js'*/ 'server-main.js',
        libraryTarget: "umd",
        path:__dirname+'/node/source',
        publicPath:'/static/'
    },
    mode: 'development',
    externals: [nodeExternals()],
    module: {
        rules: [
            {
                test: /\.jsx$/, use: {
                    loader: 'babel-loader',
                    options: {
                        cacheDirectory: true,
                        presets: ['@babel/preset-react'],
                        plugins: [

                        ]
                    },
                }
            },
            {
                test: /\.s?css$/,
                use: [MiniCssExtractPlugin.loader,
                    {
                        loader: 'css-loader',
                        options: {
                            modules: {
                                mode: 'local',
                                localIdentName: '[name]__[local]',
                            }
                        }
                    },
                    'sass-loader'
                ]
            },
            {
                test: /\.(jpg|png|gif)$/,
                use: [
                    {
                        loader: "file-loader",
                        options: {
                            esModule: false,
                            name: '[name].[ext]',
                            // publicPath: '/assets/'
                        }
                    }
                ]
            }, {
                test: /\.(ttf|eot|woff|woff2|svg)$/,
                use: "file-loader"
            }
        ]
    },
    resolve: {
        extensions: ['.js', '.jsx','.css','.scss']
    },
    plugins: [
        new MiniCssExtractPlugin(
            {filename: '[name].[contenthash:6].css'}
        )
    ]
}
